<link rel="stylesheet" href="<?php echo STATIC_URL.'/backend/css/notice.css'?>" />
<?php $this->load->view('templates/backend/lib'); ?>
<?php $result = json_decode($noidung);?>

<script>
function sending(){
    var phone       = "<?php echo $phone[0];?>";
    var message     = <?php echo ($result)?json_encode($result):'';?>;
    
    var str1     = $("#airline").text() +'. '+$("#paxname").text()+'. '+$("#message").text()+'. '+$("#total").text();
    var str3     = '';
    if($("#hanhly").val()!=""){
        str3    =   str1+'. Hanh ly: '+$("#hanhly").val()+"\n";
    } else {
        str3    =   str1;
    }
    
    var str4    =  str3 + '\n\nBẠN CHẮC CHẮN MUỐN GỞI NỘI DUNG TIN NHẮN NÀY CHO SDT '+phone;
    if (!confirm(str4)) {
        return false;
    }
    //233 ki tu

    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Vui lòng chờ");
    setTimeout(function () {
        $.ajax(
            {
                url : '/auth/bookhistory/sendsms',
                type: "POST",
                data : { phone: phone, message:message,hanhly:$("#hanhly").val()},
                cache: true,
                beforeSend: function(){
                    $("#success").html("<img src='<?php echo STATIC_URL;?>/backend/images/icon/loading-2.gif' /> <br/> Đang xử lí");
                },
                success:function(data)
                {
                    setTimeout(function () {
                        if(data==0){
                            $("#success").html("Gởi tin nhắn thành công!");
                            setTimeout(function () {
                                closeFancy();
                            },2000);
                            
                        } else {
                            $("#success").html("Gởi tin nhắn thất bại!");
                        }
                    },2000);
                },
                error: function() 
                {
                    $("#success").html("Gởi tin nhắn thất bại!");
                }
            });
     },2000);
}
function closeFancy(){
    parent.jQuery.fancybox.close();
}
</script>

<div id="container2">
    <h3 id="nav2" class="logo">
        <a id="logo">THÔNG TIN GỞI TIN NHẮN</a>
    </h3>
    <div id="wufoo-mz9i3ib0wkzqls">
        <?php
            if($checker){
        ?>
                <div style="padding-left:10px">
                    Số điện thoại: <?php echo $phone[0]; ?><br/>
                    <div id="content-sms">
                        Nội dung tin nhắn : <br/>
                            <span id="airline"><?php echo ($result->airline)?$result->airline.',':'';?><?php echo ($result->pnr)?'Code: '.$result->pnr:'';?></span>. 
                            <span id="paxname"><?php echo ($result->paxname)?implode(", ", $result->paxname):'';  ?></span>. 
                            <span id="message"><?php echo ($result->message)?implode(". ",$result->message):'';  ?></span>. 
                            <span id="total"><?php echo ($result->total)?'Gia: '.$result->total:'';  ?></span><br/>
                            <?php echo form_input(array('name' => 'hanhly', 'id' => 'hanhly', 'value' => '','placeholder'=>$this->lang->line('trunk'))); ?>
                        <span id="hanhli-hidden"></span>
                    </div>
                </div>
                <div class="top-button">
                        <?php echo form_button(array('id' => 'submit', 'name' => 'submit', 'content' => $this->lang->line('continue'),'class' => 'btn btn-primary','onclick'=>'sending()')); ?>
                        <?php echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'closeFancy()')); ?>
                </div>
                <div id="success"></div>
        <?php
            } else {
                echo '<p style="text-align: center;">BOOKING NÀY KHÔNG PHẢI DO BẠN ĐẶT! <br/>BẠN KHÔNG THỂ GỞI!</p>';
                echo '<div class="top-button">'.form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn','onclick'=>'closeFancy()')).'</div>';
            }
        ?>
    </div>
</div>
